home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cuj1008.zip / 1008048A < prev    next >
Text File  |  1992-05-15  |  4KB  |  104 lines

  1. /*                    Listing 1                     */
  2. /*****************************************************
  3.                 Name: SRF_TRNS.C
  4.          Description: Library of functions for the
  5.                       rotation and translation of
  6.                       surface equation coefficients
  7. Global Function List: srf_rotate, srf_trans
  8.          Portability: Standard C
  9. *****************************************************/
  10.  
  11. #include <stdlib.h>
  12. #include <srf_trns.h>
  13.  
  14. /*****************************************************
  15.        Name: srf_rotate
  16.  Parameters: Co - 4x4 matrix of original coefficients
  17.              Cr - 4x4 matrix of rotated coefficients
  18.              R - 3x3 matrix of coordinant rotation of
  19.              new system with respect to the original
  20. Description: Rotate a surface by a given coordinant
  21.              transformation.  Second order surfaces
  22.              are in the form,
  23.              0 = C00 + C01x + C02y + C03z + C11x² +
  24.              C22y² + C33z² + C12xy + C23yz + C13xz
  25.              First order are in the form,
  26.              0 = C00 + C01x + C02y + C03z 
  27. *****************************************************/
  28. void srf_rotate( double **Co, double **Cr,
  29.       double **R )
  30.    {
  31.    size_t i, j, k, m;
  32.  
  33.    /* Get the constant term. */
  34.    Cr[0][0] = Co[0][0];
  35.  
  36.    /* The squared terms. C11, C22, C33 */
  37.    for ( i = 1; i < 4; i++ )
  38.       for ( j = 1; j < 4; j++ )
  39.          for ( k = 1; k < 4; k++ )
  40.             Cr[i][i] += R[i - 1][j - 1] *
  41.                   R[i - 1][k - 1] * Co[j][k];
  42.  
  43.    /* The mixed terms. C12, C13, C23 */
  44.    for ( i = 1; i < 4; i++ )
  45.       for ( j = i + 1; j < 4; j++ )
  46.          for ( k = 1; k < 4; k++ )
  47.             for ( m = 1; m < 4; m++ )
  48.                Cr[i][j] += R[i - 1][k - 1] *
  49.                      R[j - 1][m - 1] *
  50.                      Co[k][m] *
  51.                      (( k == m ) ? 2 : 1 );
  52.  
  53.    /* The linear terms. C01, C02, C03 */
  54.    for ( i = 1; i < 4; i++ )
  55.       for ( j = 1; j < 4; j++ )
  56.          Cr[0][i] += R[i - 1][j - 1] * Co[0][j];
  57.  
  58.    /* Fill up the diagonals, make matrix symetric */
  59.    for ( i = 0; i < 4; i++ )
  60.       for ( j = i + 1; j < 4; j++ )
  61.          Cr[j][i] = Cr[i][j];
  62.  
  63.    }   /* function surf_rotate */
  64.  
  65. /*****************************************************
  66.        Name: srf_trans
  67.  Parameters: Co - 4x4 matrix of original coefficients
  68.              T - array of translation vector
  69.      Return: Co is modified
  70. Description: Translate a surface by a given distance
  71.              vector.  The distance vector is defined
  72.              the the coordinate system the surface is
  73.              currently in. Second order surfaces
  74.              are in the form,
  75.              0 = C00 + C01x + C02y + C03z + C11x² +
  76.              C22y² + C33z² + C12xy + C23yz + C13xz
  77.              First order are in the form,
  78.              0 = C00 + C01x + C02y + C03z 
  79. *****************************************************/
  80. void srf_trans( double **Co, double *T )
  81.    {
  82.    size_t i, j;
  83.  
  84.    /* Get the constant term. C00 */
  85.    for ( i = 0; i < 4; i++ )
  86.       for ( j = i; j < 4; j++ )
  87.          Co[0][0] += (( i == 0 ) ? 1.0 :
  88.                T[i - 1] ) * (( j == 0 ) ? 0.0 :
  89.                T[j - 1] ) * Co[i][j];
  90.  
  91.    /* Get the single terms.  C01, C02, C03 */
  92.    for ( i = 1; i < 4; i++ )
  93.       for ( j = 1; j < 4; j++ )
  94.          Co[0][i] += T[j - 1] * Co[j][i] *
  95.                (( i == j ) ? 2.0 : 1.0 );
  96.  
  97.    /* Fill up the diagonals, make matrix symetric */
  98.    for ( i = 0; i < 4; i++ )
  99.       for ( j = i + 1; j < 4; j++ )
  100.          Co[j][i] = Co[i][j];
  101.  
  102.    }   /* function surf_tran */
  103. /* End of File */
  104.